<div id="LeavesPage">
    <div class="post">
        <h2 class="title">Leave schedule</h2>
        <div class="entry">
            <script>
                $(function() {
                    $( "#leave_datepicker1" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
                $(function() {
                    $( "#leave_datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
            </script>

            <input type="button" value="Add new" onclick="show('#new_leave')"/>


            <?php
           // if ($this->session->userdata("admin")) {
            ?>
                <input type="button" value="Search" onclick="show('#searchLeaves')"/>
                <input type="button" value="Clear Search" onclick="clearSearch()"/>
            <?php
          //  }
            ?>
            <div id="leave_schedule_result" class="info">
                <?= $message ?>
            </div>
            <script type="text/javascript">
                function searchLeaves(num){
                    field=document.getElementById("searchLeavesForm"+num).field.value;
                    search=document.getElementById("searchLeavesForm"+num).search.value;
                    $("#LeavesPage").load("<?= base_url(); ?>index.php?/admin_mis/leaveSchedule/"+field+"/"+search);
                }
                function clearSearch(){
                    $("#LeavesPage").load("<?= base_url(); ?>index.php?/admin_mis/leaveSchedule/");
                }
            </script>
            <div id="new_leave" style="display: none;margin-bottom: 10px;">
                <?php $data['id'] = "doc_form" ?>
                <?= form_open_multipart('mis/saveLeaveSchedule', $data); ?>
                <table>
                    <tr class="darker"><td class="half">PNO</td><td><input type="text" class="wide" name="PNO" value="<?php echo set_value('PNO'); ?>"  /></td> </tr>
                    <tr class="lighter"><td class="half">Names</td><td><input type="text" class="wide" name="names" value="<?php echo set_value('names'); ?>" /> </td> </tr>
                    <tr class="lighter"><td class="half">Department</td><td>
                            <select name="department">
                                <?php foreach ($department as $type): ?>
                                    <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                <?php endforeach; ?>
                                </select>
                            </td> </tr>
                        <tr class="darker"><td class="half">Type of leave</td><td><input type="text" class="wide" name="type_of_leave" value="<?php echo set_value('type_of_leave'); ?>" /></td> </tr>
                        <tr class="lighter"><td class="half">No of days</td><td><input type="text" class="wide" name="no_of_days" value="<?php echo set_value('no_of_days'); ?>" /></td> </tr>
                        <tr class="darker"><td class="half">Start date</td><td><input type="text" class="wide" name="start_date"  value="<?php echo set_value('start_date'); ?>" id="leave_datepicker1"/></td> </tr>
                        <tr class="lighter"><td class="half">End date</td><td><input type="text" class="wide" name="end_date"  value="<?php echo set_value('end_date'); ?>" id="leave_datepicker2"/></td> </tr>
                        <tr class="darker"><td class="half">Replacement</td><td><input type="text" class="wide" name="replacement"  value="<?php echo set_value('replacement'); ?>"/></td> </tr>
                        <tr class="lighter"><td>Handover note</td><td><input type="file" class="wide"  name="userfile" /></td> </tr>
                        <tr><td colspan="2" style="text-align: right">
                                <input type="submit" value="Submit" />
                                <input type="button" value="Cancel" onclick="hide('#new_leave')"/>
                            </td></tr>
                    </table>
                    </form>
                </div>
                <div id="searchLeaves" style="display: none;margin-bottom: 10px;">
                    <form id="searchLeavesForm1">
                        <input type="hidden" name="field" value="department" />
                        <table>
                            <tr class="darker"><td class="half">Search by department</td>
                                <td><select name="search">
                                    <?php foreach ($department as $type): ?>
                                        <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                    <?php endforeach; ?>
                                    </select></td>
                            </tr>

                            <tr><td colspan="2" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchLeaves(1)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchLeaves')"/>
                                </td></tr>

                        </table>
                    </form>
                    <form id="searchLeavesForm2">
                        <table>
                            <tr class="darker"><td class="half">Select search criteria</td>
                                <td><select name="field">
                                        <option  value='all'>All</option>
                                        <option  value='PNO'>PNO</option>
                                        <option  value='names'>Names</option>
                                        <option  value='type_of_leave'>Type of leave</option>
                                        <option  value='replacement'>Replacement</option>
                                        <option  value='added_by'>Added by</option>
                                    </select></td>
                                <td><input type="text" name="search" class="wide"  value="<?php echo set_value('added_by'); ?>" /></td>
                            </tr>

                            <tr><td colspan="3" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchLeaves(2)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchLeaves')"/>
                                </td></tr>

                        </table>
                    </form>
                </div>
                <div id="all_docs">
                <?= $tablet ?>
                <?= $pagina ?>
            </div>

        </div>
    </div>
</div>